import { BasicResp } from './types';
import useHttp from './useHttp';

export interface RegParams {
  username: string;
  password: string;
  email: string;
}
export const reqUserRegister = (params: RegParams) => {
  return useHttp<BasicResp<null>>({
    url: `/v1/user`,
    method: 'post',
    data: { ...params },
  });
};

export interface LoginParams {
  username: string;
  password: string;
}
export interface LoginData {
  info: UserInfo;
  token: string;
}
export interface UserInfo {
  id: number;
  create_time: string;
  update_time: string;
  username: string;
  email: string;
  role: string;
}
export const regUserLogin = (params: LoginParams) => {
  return useHttp<BasicResp<LoginData>>({
    url: `/v1/user/login`,
    method: 'post',
    data: { ...params },
  });
};
export interface UserListData {
  list: UserInfo[];
  total: number;
}

// axios封装完毕
export const reqUserList = (page: number, size: number) => {
  return useHttp<BasicResp<UserListData>>({
    url: `/admin/v1/user`,
    method: 'get',
    params: { page, size },
  });
};
// register界面

export const reqUserAdd = (params: RegParams) => {
  return useHttp<BasicResp<null>>({
    url: `/v1/userAdd`,
    method: 'post',
    data: {
      ...params,
    },
  });
};

export const reqUserDel = (id: number) => {
  return useHttp<BasicResp<null>>({
    url: `/admin/v1/user/${id}`,
    method: 'delete',
  });
};
